﻿/* Generic Functions */

function newpage() {
    window.location = newLocation;
}


/* OnLoad Events */

$(document).ready(function () {
    $(document.body).hide();

    // Fade out page on link click
    $('a').click(function (e) {
        e.preventDefault();
        newLocation = this.href;
        $(document.body).fadeOut(300, newpage);
    });


    /* BEGIN PAGE SPECIFIC STUFF BEFORE PAGE DISPLAY */
    if (location.pathname.substring(1).toUpperCase() == "CONTACTUS.ASPX") {
        // Populate default form values onload
        $('input, textarea').each(function () { if ($(this).val() == '') { $(this).val($(this).attr('data-default')); } });

        // Set input default values
        $('input, textarea').bind('focusin', function () { if ($(this).val() == $(this).attr('data-default')) { $(this).val(''); } });
        $('input, textarea').bind('focusout', function () { if ($(this).val() == '') { $(this).val($(this).attr('data-default')); } });

        $("textarea").keypress(function () {
            if ($(this).val().length > $(this).attr('data-maxlen')) {
                $(this).val($(this).val().substr(0, $(this).attr('data-maxlen')));
            }
        });

        // In case user uses browser copy/paste function
        window.setInterval(function () {
            $("textarea").each(function () {
                if ($(this).val().length > $(this).attr('data-maxlen')) {
                    $(this).val($(this).val().substr(0, $(this).attr('data-maxlen')));
                }
            });
        }, 500);

        // Set to defaults null onsubmit
        $('form').submit(function () {
            $(document.body).fadeOut(300);
            $('input, textarea').each(function () { if ($(this).val() == $(this).attr('data-default')) { $(this).val('') }; });
        });
    }
    /* END PAGE SPECIFIC STUFF BEFORE PAGE DISPLAY */


    $(document.body).fadeIn(500);



    /* BEGIN PAGE SPECIFIC STUFF AFTER PAGE DISPLAY */
    if (location.pathname.substring(1).toUpperCase() == "ABOUTUS.ASPX") {

        // Fancy map stuff
        var layer = new L.StamenTileLayer("toner");
        var map = new L.Map("aboutus_map", {
            center: new L.LatLng(-32.05057, 115.83229),
            zoom: 10
        });
        map.addLayer(layer);


        var sr = {
            "type": "Feature",
            "properties": {
                "popupContent": "South of the River",
                "style": {
                    fillColor: "#FC4E2A",
                    weight: 2,
                    opacity: 1,
                    color: "white",
                    dashArray: "3",
                    fillOpacity: 0.5
                }
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [

                        [
                            [115.73880000000000, -32.05115300000000],
                            [115.78623200000000, -32.01331600000000],
                            [115.83738700000000, -32.00312700000000],
                            [115.96813900000000, -31.89504900000000],
                            [116.03680400000000, -32.11805600000000],
                            [115.76489200000000, -32.15585000000000],
                            [115.73880000000000, -32.05115300000000]
                        ]

                ]
            }
        };

        L.geoJson(sr, {
            style: function (feature) {
                return feature.properties && feature.properties.style;
            }
        }).addTo(map);
    }
    /* END PAGE SPECIFIC STUFF AFTER PAGE DISPLAY */


    // Set page header/nav buttons fixed at top
    $("#top_nav_container").sticky();

    $("form").disabled = true; // ASP.Net view state validation bug

});